
import React from 'react'
import { HashRouter, Route, Redirect, Switch } from 'react-router-dom'
import NewsSandBox from '../views/NewsSandBox'
import Login from '../views/login/Login'
import { deciphering, encryption } from '../util/Util.js';
export default function IndexRouter(props) {
  const isLogin = () => {
    if ((localStorage.getItem("userInfo") !== null)) {
      if (new Date().getTime() - JSON.parse(deciphering(localStorage.getItem("userInfo"))).createtime < 259200000) {
        return true
      }
    }
    return false
  }
  function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') c = c.substring(1, c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
  }

  return (
    <HashRouter>

      <Switch>
        <Route path="/login" component={Login} />
        <Route path="/" render={() =>
          isLogin() ? <NewsSandBox /> : <Redirect to="/login"></Redirect>
        }></Route>
      </Switch>
    </HashRouter>
  )
}